package BinarySearch;

public class _374_GuessNumberHigherorLower {
    //simulate the guess method
    public int guess(int i) {
        return 0;
    }
    //hint:be careful of low + high overflow
    public int guessNumber(int n) {
        int low = 1, high = n;
        int middle = low + (high - low) / 2;
        int ges = guess(middle);
        while (ges != 0) {
            if (ges == 1) {
                low = middle + 1;
                middle = low + (high - low) / 2;
            } else if(ges == -1){
                high = middle - 1;
                middle = low + (high - low) / 2;
            }
            ges = guess(middle);
        }
        return middle;
    }
}
